﻿
@Html.DevExpress().GridView(
settings =>
{
    
    settings.Name = "gridView";
    settings.InitDefaultPagerGridViewSettings();
    settings.EnableAlternatingRowColor();
    settings.EnableRowIndexColumn();
    settings.CallbackRouteValues = new { Controller = "File", Action = "ListPartialView", id = Html.ViewContext.RouteData.Values["id"] };
    
    settings.KeyFieldName = "FileId";

    
    
    settings.Columns.Add(col =>
    {
        col.CellStyle.HorizontalAlign = HorizontalAlign.Left;
        col.Caption = "文件名";
        col.SetDataItemTemplateContent(c =>
        {
            string id = DataBinder.Eval(c.DataItem, "FileId").ToString();
            string filename = DataBinder.Eval(c.DataItem, "FileName2").ToString();
            bool isnew = (bool)DataBinder.Eval(c.DataItem, "IsNew");
            if (isnew)
            {
                ViewContext.Writer.Write("<span style='color:red;text-align:center'>新</span>&nbsp;");
            }
            ViewContext.Writer.Write(
                Html.ActionLink(filename, "DownLoad", new { id = id })
            );
        }
        );
    });
    //string file-type = DataBinder.Eval(c.DataItem, "FileName2").ToString();
    settings.AddFileKindColumn();
    
    settings.Columns.Add("FileDate", "文件日期", MVCxGridViewColumnType.DateEdit).PropertiesEdit.DisplayFormatString = "yyyy-MM-dd HH:mm";
    
    settings.Columns.Add("OperName", "上传人");
    settings.Columns.Add("Note", "描述");

    settings.Columns.Add(col =>
    {
        col.CellStyle.Paddings.Padding = 1;
        col.CellStyle.Paddings.PaddingLeft = 5;
        col.Caption = "";
        col.Width = 150;
        col.CellStyle.HorizontalAlign = HorizontalAlign.Center;

        col.SetDataItemTemplateContent(c =>
        {
            int userId = DataBinder.Eval(c.DataItem, "FileId").ToString().ToInt();
            //string upload_user = DataBinder.Eval(c.DataItem, "FileId").ToSafeString();
            string account = DataBinder.Eval(c.DataItem, "OperCode").ToString();
            bool viewed = WebcarDataProvider.DB.user_view_response.Find("file", userId, CurrentUser.LoginUserID) != null;
            if (viewed)
            {
                ViewContext.Writer.Write("已回复&nbsp;");
            }
            else
            {
                ViewContext.Writer.Write(
                    Html.ActionLink("[回复意见]", "View", new { id = userId }, new { @style = "color:red" }) + "&nbsp;"
                );
            }
            if (account == CurrentUser.LoginUserID||CurrentUser.IsSuperUser)
            {
                ViewContext.Writer.Write(
                    Html.ActionLink("[查看回复]", "ViewList", new { id = userId }) + "&nbsp;"
                );
                ViewContext.Writer.Write(
                    Html.ActionLink("[删除]", "Delete", new { id = userId }, new { onclick = "return confirm('是否要删除此文件?')" })
                );
            }
        }
        );
    });
    
    //settings.AddYesNoColumn2("loginenable", "是否启用");
    //settings.AddYesNoColumn("is_super", "是否管理员");
}).BindEF((s, e) => {
        e.KeyExpression = "FileId";
        e.QueryableSource = this.GetFileList();
        e.DefaultSorting = "FileDate desc";
    }).GetHtml()
